package com.asset.dispoal.flawPool.service.commom;

import com.asset.dispoal.flawPool.domain.db.entity.FlawPoolDo;
import com.asset.dispoal.flawPool.domain.db.mapper.FlawPoolMapper;
import com.asset.dispoal.flawPool.dto.FlawPoolRequest;
import com.asset.dispoal.flawPool.service.converter.FlawPoolConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/5/23$
 */
@Component
public class InsertFlawPoolCommand implements BaseCommand<FlawPoolRequest, Result> {

    @Autowired
    FlawPoolMapper flawPoolMapper;

    @Autowired
    BaseIdeable<String> snowFlake;

    @Override
    public Result execute(FlawPoolRequest flawPoolRequest) {

        FlawPoolDo flawPoolDo = FlawPoolConverter.INSTANCE.reqToDo(flawPoolRequest);
        flawPoolDo.setId(snowFlake.generateId());
        flawPoolMapper.insert(flawPoolDo);

        return Result.ok();
    }
}
